package face.pay.util;

import org.apache.commons.lang3.time.DateUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: zkj
 * @Date: 2019/7/27 17:09
 * @Description:
 */
public class TimeUtils extends DateUtils {


    /**
     * 精确到天
     */
    private static final SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd");


    /**
     * 精确到秒
     */
    private static final SimpleDateFormat secondFormat =   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     6      * Constant that contains the amount of milliseconds in a second
     7      */
      static final long ONE_SECOND = 1000L;

              /**
        * Converts milliseconds to seconds
        * @param timeInMillis
        * @return The equivalent time in seconds
        */
      public static int toSecs(long timeInMillis) {
         return (int)Math.ceil((double)timeInMillis / ONE_SECOND);
     }

             /**
      * Converts seconds to milliseconds, with a precision of 1 second
       * @param timeInSecs the time in seconds
       * @return The equivalent time in milliseconds
       */
        public static long toMillis(int timeInSecs) {

            return timeInSecs * ONE_SECOND;
        }

             /**
       * Converts a long seconds value to an int seconds value and takes into account overflow
       * from the downcast by switching to Integer.MAX_VALUE.
       * @param seconds Long value
       * @return Same int value unless long > Integer.MAX_VALUE in which case MAX_VALUE is returned
       */
     public static int convertTimeToInt(long seconds) {
         if (seconds > Integer.MAX_VALUE) {
                 return Integer.MAX_VALUE;
             } else {
                 return (int) seconds;
             }
     }

     public static String   dayFormat(Date date){

          return   dayFormat.format(date);


     }
}
